package org.social.db.bean;

import com.sojoys.artifact.factory.bytebuff.IByteBuff;
import org.social.db.cache.WechatShopOrderCache;
import org.apache.commons.lang3.ArrayUtils;
import static org.social.db.StaticResource.WechatShopOrderResource.*;
import com.sojoys.artifact.build.data.base.BasePojo;
import java.sql.SQLException;
import com.sojoys.artifact.tools.ToolMap;
import com.sojoys.artifact.tools.SK_Plus;
import com.sojoys.artifact.tools.ToolCopy;
import java.sql.ResultSet;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import com.sojoys.artifact.constant.DataModelKeyEnum;
import static org.social.db.StaticResource.WechatShopOrderResource.*;
/**
 * 微信积分兑换商城
 */
public class WechatShopOrder extends BasePojo<WechatShopOrder> {
	
	
	/**
	 * 索引值
	 */
	private String[] indexValues = new String[1];
	
	/**
	* 订单号
	*/
	private String orderid;
	
	/**
	* 区服id
	*/
	private String serverId;
	
	/**
	* 角色id
	*/
	private int playerId;
	
	/**
	* 礼包id
	*/
	private int prizeid;
	
	/**
	* 下单时间
	*/
	private java.util.Date time;
	
	/**
	* 订单处理状态 0-失败 1-成功
	*/
	private boolean success;
	
	/**
	* create_date
	*/
	private java.util.Date createDate;
	
	/**
	* modified_date
	*/
	private java.util.Date modifiedDate;
	
	
	@Deprecated
	public static WechatShopOrder builder() {
		WechatShopOrder wechatShopOrder = new WechatShopOrder();
		return wechatShopOrder;
	}
	
	@Deprecated
	public WechatShopOrder() {
		super();
	}
	
	public WechatShopOrder(String orderid, String serverId, int playerId, int prizeid, java.util.Date time, boolean success) {
		super();
		this.orderid = orderid;
		this.serverId = serverId;
		this.playerId = playerId;
		this.prizeid = prizeid;
		this.time = time;
		this.success = success;
		this.createDate = new java.util.Date();
		this.modifiedDate = new java.util.Date();
	}
	
	/**
	 * 订单号
	 */
	public String getOrderid() {return orderid;}
	
	/**
	 * 订单号
	 */
	public WechatShopOrder setOrderid(String orderid) {this.orderid = orderid;return this;}
	
	/**
	 * 区服id
	 */
	public String getServerId() {return serverId;}
	
	/**
	 * 区服id
	 */
	public WechatShopOrder setServerId(String serverId) {this.serverId = serverId;return this;}
	
	/**
	 * 角色id
	 */
	public int getPlayerId() {return playerId;}
	
	/**
	 * 角色id
	 */
	public WechatShopOrder setPlayerId(int playerId) {this.playerId = playerId;return this;}
	
	/**
	 * 礼包id
	 */
	public int getPrizeid() {return prizeid;}
	
	/**
	 * 礼包id
	 */
	public WechatShopOrder setPrizeid(int prizeid) {this.prizeid = prizeid;return this;}
	
	/**
	 * 下单时间
	 */
	public java.util.Date getTime() {return time;}
	
	/**
	 * 下单时间
	 */
	public WechatShopOrder setTime(java.util.Date time) {this.time = time;return this;}
	
	/**
	 * 订单处理状态 0-失败 1-成功
	 */
	public boolean isSuccess() {return success;}
	
	/**
	 * 订单处理状态 0-失败 1-成功
	 */
	public WechatShopOrder setSuccess(boolean success) {this.success = success;return this;}
	
	/**
	 * create_date
	 */
	public java.util.Date getCreateDate() {return createDate;}
	
	/**
	 * create_date
	 */
	protected WechatShopOrder setCreateDate(java.util.Date createDate) {this.createDate = createDate;return this;}
	
	/**
	 * modified_date
	 */
	public java.util.Date getModifiedDate() {return modifiedDate;}
	
	/**
	 * modified_date
	 */
	protected WechatShopOrder setModifiedDate(java.util.Date modifiedDate) {this.modifiedDate = modifiedDate;return this;}
	
	
	// 代理
	
	protected Object[] getColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return SOURCE_COLUMN_NAMES;
		case PINGYING:
			return PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return HASHCODE_COLUMN_NAMES;
		case REMARKS:
			return SOURCE_COLUMN_REMARKS;
		default:
			return PINGYING_COLUMN_NAMES;
		}
	}
	
	protected Object[] getFKTableNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_TABLE_NAMES;
		case PINGYING:
			return FK_PINGYING_TABLE_NAMES;
		case HASHCODE:
			return FK_HASHCODE_TABLE_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected Object[] getFKColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_COLUMN_NAMES;
		case PINGYING:
			return FK_PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return FK_HASHCODE_COLUMN_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected String[] getBasicTypes(){
		return COLUMN_BASICTYPES;
	}
	
	protected Class[] getClassTypes(){
		return COLUMN_CLASSTYPES;
	}
	
	protected String[] getColumnTypes(){
		return COLUMN_COLUMNTYPES;
	}
	
	protected int getColumnCount(){
		return COLUMN_COUNT;
	}
	
	protected Object[] getColumeValues(){
		Object[] values = new Object[COLUMN_COUNT];
        values[0] = this.orderid;
        values[1] = this.serverId;
        values[2] = this.playerId;
        values[3] = this.prizeid;
        values[4] = this.time;
        values[5] = this.success;
        values[6] = this.createDate;
        values[7] = this.modifiedDate;
        return values;
	}
	
	public WechatShopOrder deepCopy(){
		WechatShopOrder wechatShopOrder = null;
		try {
			wechatShopOrder = (WechatShopOrder) super.clone();
		    wechatShopOrder.setTime(ToolCopy.copyObject(this.time));
		    wechatShopOrder.setCreateDate(ToolCopy.copyObject(this.createDate));
		    wechatShopOrder.setModifiedDate(ToolCopy.copyObject(this.modifiedDate));
		    // 克隆索引
		    wechatShopOrder.indexValues = ArrayUtils.clone(indexValues);
			return wechatShopOrder;
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return wechatShopOrder;
	}
	
	
	protected Map<Object, Object> toMap(Object[] keys,Map<Object, Object> map){
        map.put(keys[0], this.orderid);
        map.put(keys[1], this.serverId);
        map.put(keys[2], this.playerId);
        map.put(keys[3], this.prizeid);
        map.put(keys[4], this.time);
        map.put(keys[5], this.success);
        map.put(keys[6], this.createDate);
        map.put(keys[7], this.modifiedDate);
        return map;
    }
    
    protected WechatShopOrder createForMap(Object[] keys,Map map){
   		this.orderid = (String)map.get(keys[0]);
   		this.serverId = (String)map.get(keys[1]);
   		this.playerId = (int)map.get(keys[2]);
   		this.prizeid = (int)map.get(keys[3]);
   		this.time = (java.util.Date)map.get(keys[4]);
   		this.success = (boolean)map.get(keys[5]);
   		this.createDate = (java.util.Date)map.get(keys[6]);
   		this.modifiedDate = (java.util.Date)map.get(keys[7]);
        return this;
    }
	
	
	protected JSONObject toJSONObject(Object[] keys,JSONObject obj){
        obj.put(keys[0], this.orderid);
        obj.put(keys[1], this.serverId);
        obj.put(keys[2], this.playerId);
        obj.put(keys[3], this.prizeid);
        obj.put(keys[4], this.time);
        obj.put(keys[5], this.success);
        obj.put(keys[6], this.createDate);
        obj.put(keys[7], this.modifiedDate);
        return obj;
    }
    
    protected WechatShopOrder createForJSONObject(Object[] keys,JSONObject obj){
	    this.orderid = obj.getString(keys[0]);
	    this.serverId = obj.getString(keys[1]);
	    this.playerId = obj.getIntValue(keys[2]);
	    this.prizeid = obj.getIntValue(keys[3]);
	    this.time = obj.getDate(keys[4]);
	    this.success = obj.getBooleanValue(keys[5]);
	    this.createDate = obj.getDate(keys[6]);
	    this.modifiedDate = obj.getDate(keys[7]);
        return this;
    }
    
    
    public WechatShopOrder createForResultSet(ResultSet rs) throws SQLException{
	    this.orderid = rs.getString(SOURCE_COLUMN_NAMES[0]);
	    this.serverId = rs.getString(SOURCE_COLUMN_NAMES[1]);
	    this.playerId = rs.getInt(SOURCE_COLUMN_NAMES[2]);
	    this.prizeid = rs.getInt(SOURCE_COLUMN_NAMES[3]);
	    this.time = rs.getTimestamp(SOURCE_COLUMN_NAMES[4]);
	    this.success = rs.getBoolean(SOURCE_COLUMN_NAMES[5]);
	    this.createDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[6]);
	    this.modifiedDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[7]);
	    return this;
    }
    
    protected void writeBytes(IByteBuff byteBuf){
	    byteBuf.writeString(this.orderid);
	    byteBuf.writeString(this.serverId);
	    byteBuf.writeInt(this.playerId);
	    byteBuf.writeInt(this.prizeid);
	    byteBuf.writeDate(this.time);
	    byteBuf.writeBoolean(this.success);
	    byteBuf.writeDate(this.createDate);
	    byteBuf.writeDate(this.modifiedDate);
    }
	
	protected WechatShopOrder readBytes(IByteBuff byteBuf){
	    this.orderid = byteBuf.readString(null);
	    this.serverId = byteBuf.readString(null);
	    this.playerId = byteBuf.readInt(null);
	    this.prizeid = byteBuf.readInt(null);
	    this.time = byteBuf.readDate(null);
	    this.success = byteBuf.readBoolean(null);
	    this.createDate = byteBuf.readDate(null);
	    this.modifiedDate = byteBuf.readDate(null);
	    return this;
	}
    
    
    protected JSONObject exportFKTableMap(Object[] keys,JSONObject map,DataModelKeyEnum e){
        return map;
    }
    
    protected boolean importFKTableMap(Object[] keys,JSONObject map,DataModelKeyEnum e){
		return true;
    }
    
	
    /** 级联删除(延迟入库) */
    public boolean deleteAndSon(){
    	return false;
    }
    
    /** 级联删除(及时入库) */
    public boolean deleteAndSonAndFlush(){
    	return false;
    }
    
    /** 延迟插入数据库 */
    public WechatShopOrder insert(){
    	return WechatShopOrderCache.me().insert(this);
    }
    /** 延迟更新数据库 */
    public WechatShopOrder update(){
    	return WechatShopOrderCache.me().update(this);
    }
    /** 延迟删除数据库 */
    public boolean delete(){
    	return WechatShopOrderCache.me().delete(this);
    }
    /** 即时插入数据库 */
    public WechatShopOrder insertAndFlush(){
    	return WechatShopOrderCache.me().insertAndFlush(this);
    }
    /** 即时更新数据库 */
    public WechatShopOrder updateAndFlush(){
    	return WechatShopOrderCache.me().updateAndFlush(this);
    }
    /** 即时删除数据库 */
    public boolean deleteAndFlush(){
    	return WechatShopOrderCache.me().deleteAndFlush(this);
    }
    
    
	
	/**
	 * 同步索引值
	 */
	public WechatShopOrder syncIndexValues(){
		indexValues[0] = SK_Plus.b(getOrderid()).e();
		return this;
	}
	/**
	 * 取得索引
	 */
	public String[] getIndexValues(){
		return indexValues;
	}
	
	protected Object getPrimaryKey(){
		return getOrderid();
	}
	
	protected void setPrimaryKey(Object key){
		setOrderid((String)key);
	}
//自定义内容起始位置
//自定义内容结束位置
}